package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import entity.Course;
import entity.Elective;
import service.ISmsserivce;
import service.impl.SmsserivceImpl;

/**
 * Servlet implementation class StudentAddServlet
 */
@WebServlet(asyncSupported = true, urlPatterns = { "/UpdateCourseById" })
public class UpdateCourseById extends HttpServlet {
	
	private ISmsserivce smsservice = new SmsserivceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		
		int course_id = Integer.parseInt(request.getParameter("course_id"));
		
		Course course = new Course(course_id);
		request.getSession().setAttribute("course_id", course_id);
		try {
			List<Course> updateCourseById = smsservice.selectCourseById(course);
			request.getSession().setAttribute("updateCourseById", updateCourseById);
			response.sendRedirect("Tupdate.jsp");
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
